<template>
    <div class="app-container">
        <wms-form v-model:query-params="queryParams" :form-list="formList" @query="getList" label-width="88px"
            @export="handleExport">
        </wms-form>

        <wms-table class="table-click" :loading="loading" :data-list="taskList" :column="column" :columnResize="true"
            :pageInfo="queryParams" @get-list="getList" />
    </div>
</template>

<script setup name="Task">
import WmsTable from '@/components/WmsTable/index.vue'
import WmsForm from '@/components/WmsForm/index.vue'
import { data, column, formList } from './index.js'
import { listTask, getTask, cancelTask, addTask, updateTask } from "@/api/wms/task";
import { ref, reactive, getCurrentInstance, onMounted } from "vue";

const { proxy } = getCurrentInstance();
const queryParams = reactive(data.queryParams);
const taskList = ref([]);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const loading = ref(true);

/** 查询任务查询列表 */
function getList() {
    loading.value = true;
    listTask(queryParams).then(response => {
        taskList.value = response.rows;
        queryParams.total = response.total;
        loading.value = false;
    });
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    queryParams.dateRange = [];
    proxy.resetForm("queryRef");
    handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.taskId);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
}

/** 取消按钮操作 */
function handleDelete(row) {
    proxy.$modal.confirm('是否确认取消选中任务？').then(function () {
        return cancelTask({ ids: ids.value });
    }).then((res) => {
        if (res.code == 200) {
            proxy.$modal.msgSuccess("任务取消成功");
            getList();
        } else {
            proxy.$modal.msgError(res.msg);
        }
    }).catch(() => { });
}

/** 导出按钮操作 */
function handleExport() {
    proxy.download('wms/task/export', {
        ...queryParams
    }, `task_${new Date().getTime()}.xlsx`)
}

getList();
</script>
